import $ from 'jquery'
import {CAROUSEL} from '../config/config';
export default class Carousel{
    constructor(){
        this.$carousel = $('.J_carousel');
        this.$sliders = this.$carousel.find('.slider-item');
        this.$indicators = this.$carousel.find('.indicator-item');
        this.curIdx = 0;
    }
    init(){
        CAROUSEL.autoplay && this.autoPlay();
        this.bindEvent();
    }
    autoPlay(){
        Carousel.timer = setInterval(()=>{
            this.setIndex('next')
        },CAROUSEL.duration)
    }
    bindEvent(){

    }
    setIndex(direction){
        switch(direction){
            case 'next':
                this.curIdx = this.curIdx === this.$sliders.length - 1
                            ? 0
                            :this.curIdx +1
                break;
            case 'prev':
                this.curIdx = this.curIdx === 0
                ? this.$sliders.length - 1
                :this.curIdx - 1
                break;
            default:
                break;        
        }
        this.sliderAction(index){
            this.$sliders.eq(index).fadeIn(300).siblings().fadeOut(300);